mod_rewrite problem: $1 and $2 not substituted into target url

mod_rewrite problem: $1 and $2 not substituted into target url

am 26.01.2010 18:32:31 von Chris Brooks

--001485f7c300dbaa55047e14ac36
Content-Type: text/plain; charset=ISO-8859-1

Good morning Apache list,

I have a strange mod_rewrite problem, and I'm not sure how to solve it. I
have a RewriteRule that works correctly on one apache daemon, but doesn't
work when copied and pasted to the httpd.conf file of a second apache
daemon.

To state this differently, on the second apache daemon, mod_rewrite is
correctly matching the URL based on the regex, but it is not substituting
the back-references into the target URL.

The rule looks like this:

RewriteRule /products/(.*)/(.*)\.html$ /perl/
detail.pl?url_name=$1&model_nbr=$2

On the first server this successfully matches this request:

http://www.mydomain.com/products/whirlpool/1234567.html, and does an
internal redirect to /perl/detail.pl?url_name=whirlpool&model_nbr=1234567

On the 2nd (malfunctioning) server, it doesn't work -- although mod_rewrite
correctly matches the request to the rule, it doesn't substitute the values
inside the parentheses to $1 and $2 in the output URL. Here's what gets
written to the output of the RewriteLog on the 2nd server:

192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial]
(2) init rewrite engine with requested uri /products/whirlpool/1234567.html
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial]
(3) applying pattern '/products/(.*)/(.*)\.html$' to uri
'/products/whirlpool/1234567.html'
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial]
(2) *rewrite /products/whirlpool/1234567.**html -> /perl/
detail.pl?url_name=&model_nbr=*
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial]
(3) *split uri=/perl/detail.pl?url_name=&model_nbr= -> uri=/perl/detail.pl,
args=url_name=&model_nbr=*
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial]
(2) local path result: /perl/detail.pl
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial]
(2) prefixed with document_root to /www/perl/mydomain/htdocs/perl/detail.pl
192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [
www.mydomain.com/sid#9094fec][rid#90a8b3c/initial]
(1) go-ahead with /www/perl/mydomain/htdocs/perl/detail.pl [OK]

Note the bolded sections of the log -- the values stored in $1 and $2 are
not substituted into the final URL. On the first server, these do get
substituted AND they get written to the rewrite_log.

Here's the relevant section of the httpd.conf file for the malfunctioning
Apache daemon:

RewriteEngine On

RewriteLog /var/log/apache-perl/rewrite_log.log
RewriteLogLevel 3

RewriteRule /products/(.*)/(.*)\.html$ /perl/
detail.pl?url_name=$1&model_nbr=$2

I thought it was possible that there were conflicts with other rules, so I
removed all the other RewriteRules and made sure that there were no
..htaccess files that applied to this request. I also tried hard-coding the
url_name param to "whirlpool", on the theory that mod_rewrite might be happy
with 1 substitution param, but no dice. In this case it still declined to
substitute "1234567" for $1. This httpd.conf file has no other virtual
hosts which might be causing a conflict.

Any suggestions as to what might be going on?

Thanks,
Chris

--001485f7c300dbaa55047e14ac36
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Good morning Apache list,

I have a strange mod_rewrite problem, and =
I'm not sure how to solve it.=A0 I have a RewriteRule that works correc=
tly on one apache daemon, but doesn't work when copied and pasted to th=
e httpd.conf file of a second apache daemon.=A0






To state this differently, on the second apache daemon, mod_rewrite is =
correctly matching the URL based on the regex, but it is not substituting t=
he back-references into the target URL.

The rule looks like this: r>




RewriteRule /products/(.*)/(.*)\.html$ /perl/ l?url_name=3D$1&model_nbr=3D$2" target=3D"_blank">detail.pl?url_name=3D=
$1&model_nbr=3D$2




On the first server this successfully matches this request:

ref=3D"http://www.mydomain.com/products/whirlpool/1234567.ht ml" target=3D"_=
blank">http://www.mydomain.com/products/whirlpool/1234567.ht ml
, and doe=
s an internal redirect to /perl/ lpool&model_nbr=3D1234567" target=3D"_blank">detail.pl?url_name=3Dwhirl=
pool&model_nbr=3D1234567









On the 2nd (malfunctioning) server, it doesn't work -- although mod=
_rewrite correctly matches the request to the rule, it doesn't substitu=
te the values inside the parentheses to $1 and $2 in the output URL.=A0 Her=
e's what gets written to the output of the RewriteLog on the 2nd server=
:






192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [ omain.com/sid#9094fec][rid%2390a8b3c/initial" target=3D"_blank">www.mydomai=
n.com/sid#9094fec][rid#90a8b3c/initial
] (2) init rewrite engine with re=
quested uri /products/whirlpool/1234567.html







192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [ n.com/sid#9094fec][rid%2390a8b3c/initial" target=3D"_blank">www.mydomain.co=
m/sid#9094fec][rid#90a8b3c/initial
] (3) applying pattern '/products=
/(.*)/(.*)\.html$' to uri '/products/whirlpool/1234567.html' >






192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [ n.com/sid#9094fec][rid%2390a8b3c/initial" target=3D"_blank">www.mydomain.co=
m/sid#9094fec][rid#90a8b3c/initial
] (2) rewrite /products/whirlpool/=
1234567.
html -> /perl/ ;model_nbr=3D" target=3D"_blank">detail.pl?url_name=3D&model_nbr=3D=








192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [ n.com/sid#9094fec][rid%2390a8b3c/initial" target=3D"_blank">www.mydomain.co=
m/sid#9094fec][rid#90a8b3c/initial
] (3) split uri=3D/perl/ "http://detail.pl?url_name=3D&model_nbr=3D" target=3D"_blank">detail.pl=
?url_name=3D&model_nbr=3D
-> uri=3D/perl/ l.pl" target=3D"_blank">detail.pl, args=3Durl_name=3D&model_nbr=3D<=
/b>







192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [ n.com/sid#9094fec][rid%2390a8b3c/initial" target=3D"_blank">www.mydomain.co=
m/sid#9094fec][rid#90a8b3c/initial
] (2) local path result: /perl/ f=3D"http://detail.pl" target=3D"_blank">detail.pl







192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [ n.com/sid#9094fec][rid%2390a8b3c/initial" target=3D"_blank">www.mydomain.co=
m/sid#9094fec][rid#90a8b3c/initial
] (2) prefixed with document_root to =
/www/perl/mydomain/htdocs/perl/ k">detail.pl







192.168.1.3 - - [26/Jan/2010:10:17:06 -0600] [ n.com/sid#9094fec][rid%2390a8b3c/initial" target=3D"_blank">www.mydomain.co=
m/sid#9094fec][rid#90a8b3c/initial
] (1) go-ahead with /www/perl/mydomai=
n/htdocs/perl/ =
[OK]








Note the bolded sections of the log -- the values stored in $1 and $2 a=
re not substituted into the final URL.=A0 On the first server, these do get=
substituted AND they get written to the rewrite_log.

Here's the=
relevant section of the httpd.conf file for the malfunctioning Apache daem=
on:








RewriteEngine On

RewriteLog /var/log/apache-perl/rewrite_log.log=

RewriteLogLevel 3

RewriteRule /products/(.*)/(.*)\.html$=20
/perl/ =3D"_blank">detail.pl?url_name=3D$1&model_nbr=3D$2

I thought=
it was possible that there were conflicts with other rules, so I removed a=
ll the other RewriteRules and made sure that there were no .htaccess files =
that applied to this request.=A0 I also tried hard-coding the url_name para=
m to "whirlpool", on the theory that mod_rewrite might be happy w=
ith 1 substitution param, but no dice.=A0 In this case it still declined to=
substitute "1234567" for $1.=A0 This httpd.conf file has no othe=
r virtual hosts which might be causing a conflict.







Any suggestions as to what might be going on?

Thanks,
Chris r>

--001485f7c300dbaa55047e14ac36--

Re: mod_rewrite problem: $1 and $2 not substituted into

am 27.01.2010 11:16:26 von Krist van Besien

On Tue, Jan 26, 2010 at 6:32 PM, Chris Brooks wrote:


> Any suggestions as to what might be going on?

You are not using any sections by chance, are you?

Krist

--
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: mod_rewrite problem: $1 and $2 not substituted into

am 27.01.2010 13:16:16 von Chris Brooks

--001485f453f0b02abb047e245fe5
Content-Type: text/plain; charset=ISO-8859-1

Good morning Krist,

Thank you very much for your reply.

No, I don't have any blocks in the httpd.conf, although this is a
mod_perl enabled apache daemon.

Thanks,
Chris

On Wed, Jan 27, 2010 at 5:16 AM, Krist van Besien > wrote:

> On Tue, Jan 26, 2010 at 6:32 PM, Chris Brooks wrote:
>
>
> > Any suggestions as to what might be going on?
>
> You are not using any sections by chance, are you?
>
> Krist
>
> --
> krist.vanbesien@gmail.com
> krist@vanbesien.org
> Bremgarten b. Bern, Switzerland
> --
> A: It reverses the normal flow of conversation.
> Q: What's wrong with top-posting?
> A: Top-posting.
> Q: What's the biggest scourge on plain text email discussions?
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

--001485f453f0b02abb047e245fe5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Good morning Krist,

Thank you very much for your reply.

No, I=
don't have any <perl> blocks in the httpd.conf, although this is=
a mod_perl enabled apache daemon.

Thanks,
Chris

s=3D"gmail_quote">

On Wed, Jan 27, 2010 at 5:16 AM, Krist van Besien < href=3D"mailto:krist.vanbesien@gmail.com">krist.vanbesien@gm ail.com>=
wrote:
px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"=
>

On Tue, Jan 26, 2010 at 6:32 PM, Chris Brooks < =3D"mailto:madbury@gmail.com">madbury@gmail.com> wrote:





> Any suggestions as to what might be going on?



You are not using any <perl> sections by chance, are you?



Krist



--

<=
br>


Bremgarten b. Bern, Switzerland

--

A: It reverses the normal flow of conversation.

Q: What's wrong with top-posting?

A: Top-posting.

Q: What's the biggest scourge on plain text email discussions?



------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--001485f453f0b02abb047e245fe5--

Re: mod_rewrite problem: $1 and $2 not substituted into

am 27.01.2010 13:53:47 von Eric Covener

On Tue, Jan 26, 2010 at 12:32 PM, Chris Brooks wrote:
> Good morning Apache list,
>
> I have a strange mod_rewrite problem, and I'm not sure how to solve it.=
=A0 I
> have a RewriteRule that works correctly on one apache daemon, but doesn't
> work when copied and pasted to the httpd.conf file of a second apache
> daemon.
>

What are the versions involved?

--=20
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: mod_rewrite problem: $1 and $2 not substituted into

am 27.01.2010 14:38:17 von Chris Brooks

--001485f7c30000cfd4047e2585b9
Content-Type: text/plain; charset=ISO-8859-1

Hi Eric,

Thanks for the note. Both apache and mod_perl are up-to-date:

[root@data2 ~]# /usr/local/apache-perl/bin/httpd -v
Server version: Apache/1.3.41 (Unix)
Server built: Sep 2 2009 15:34:13

[root@data2 ~]# perl -Mmod_perl -le 'print mod_perl->VERSION'
1.31

Thanks,
Chris

On Wed, Jan 27, 2010 at 7:53 AM, Eric Covener wrote:

> On Tue, Jan 26, 2010 at 12:32 PM, Chris Brooks wrote:
> > Good morning Apache list,
> >
> > I have a strange mod_rewrite problem, and I'm not sure how to solve it.
> I
> > have a RewriteRule that works correctly on one apache daemon, but doesn't
> > work when copied and pasted to the httpd.conf file of a second apache
> > daemon.
> >
>
> What are the versions involved?
>
> --
> Eric Covener
> covener@gmail.com
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

--001485f7c30000cfd4047e2585b9
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Eric,

Thanks for the note.=A0 Both apache and mod_perl are up-to-=
date:

[root@data2 ~]# /usr/local/apache-perl/bin/httpd -v
Server =
version: Apache/1.3.41 (Unix)
Server built:   Sep=A0 2 2009 15:34:13=




[root@data2 ~]# perl -Mmod_perl -le 'print mod_perl->VERSION' >1.31

Thanks,
Chris

On Wed, Jan=
27, 2010 at 7:53 AM, Eric Covener < covener@gmail.com">covener@gmail.com> wrote:


204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
>On Tue, Jan 26, 2010 at 12:32 PM, Chris Brooks < ry@gmail.com">madbury@gmail.com> wrote:



> Good morning Apache list,

>

> I have a strange mod_rewrite problem, and I'm not sure how to solv=
e it.=A0 I

> have a RewriteRule that works correctly on one apache daemon, but does=
n't

> work when copied and pasted to the httpd.conf file of a second apache<=
br>
> daemon.

>



What are the versions involved?



--

Eric Covener





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--001485f7c30000cfd4047e2585b9--

Re: mod_rewrite problem: $1 and $2 not substituted into

am 27.01.2010 14:43:55 von Eric Covener

On Wed, Jan 27, 2010 at 8:38 AM, Chris Brooks wrote:
> Hi Eric,
>
> Thanks for the note.=A0 Both apache and mod_perl are up-to-date:
>
> [root@data2 ~]# /usr/local/apache-perl/bin/httpd -v
> Server version: Apache/1.3.41 (Unix)
> Server built:   Sep=A0 2 2009 15:34:13

Both systems are 1.3?

--=20
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: mod_rewrite problem: $1 and $2 not substituted into

am 27.01.2010 14:51:38 von Chris Brooks

--001485f45450c3b396047e25b432
Content-Type: text/plain; charset=ISO-8859-1

Hi Eric,

Yes, both are 1.3.

I don't have Apache2.pm -- the mod_perl2 module -- installed.

[root@data2 ~]# perl -MApache2 -le 'print mod_perl->VERSION'
Can't locate Apache2.pm in @INC (@INC contains: /www/perl/
/usr/local/lib/perl5/5.8.7/i686-linux /usr/local/lib/perl5/5.8.7
/usr/local/lib/perl5/site_perl/5.8.7/i686-linux
/usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl .).

Thank you for taking the time to help!
Chris

On Wed, Jan 27, 2010 at 8:43 AM, Eric Covener wrote:

> On Wed, Jan 27, 2010 at 8:38 AM, Chris Brooks wrote:
> > Hi Eric,
> >
> > Thanks for the note. Both apache and mod_perl are up-to-date:
> >
> > [root@data2 ~]# /usr/local/apache-perl/bin/httpd -v
> > Server version: Apache/1.3.41 (Unix)
> > Server built: Sep 2 2009 15:34:13
>
> Both systems are 1.3?
>
> --
> Eric Covener
> covener@gmail.com
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

--001485f45450c3b396047e25b432
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Eric,

Yes, both are 1.3.

I don't have Apache2.pm -- th=
e mod_perl2 module -- installed.

[root@data2 ~]# perl -MApache2 -le =
'print mod_perl->VERSION'
Can't locate Apache2.pm in @INC=
(@INC contains: /www/perl/ /usr/local/lib/perl5/5.8.7/i686-linux /usr/loca=
l/lib/perl5/5.8.7 /usr/local/lib/perl5/site_perl/5.8.7/i686-linux /usr/loca=
l/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl .).



Thank you for taking the time to help!
Chris

ail_quote">On Wed, Jan 27, 2010 at 8:43 AM, Eric Covener =
<>
w=
rote:


204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
>On Wed, Jan 27, 2010 at 8:38 AM, Chris Brooks < y@gmail.com">madbury@gmail.com> wrote:



> Hi Eric,

>

> Thanks for the note.=A0 Both apache and mod_perl are up-to-date:

>

> [root@data2 ~]# /usr/local/apache-perl/bin/httpd -v

> Server version: Apache/1.3.41 (Unix)

> Server built:   Sep=A0 2 2009 15:34:13



Both systems are 1.3?



--

Eric Covener





------------------------------------------------------------ ---------

The official User-To-User support forum of the Apache HTTP Server Project.<=
br>
See <URL: lank">http://httpd.apache.org/userslist.html> for more info.

To unsubscribe, e-mail: g">users-unsubscribe@httpd.apache.org

=A0 " =A0 from the digest: @httpd.apache.org">users-digest-unsubscribe@httpd.apache.org

For additional commands, e-mail: org">users-help@httpd.apache.org






--001485f45450c3b396047e25b432--